<template>

    <div class="login-container">
        <el-form  status-icon   label-width="100px" class="demo-ruleForm"  >
            <div style="margin-left: 60px">登录系统</div>
            <br>
            <el-form-item label="姓名" prop="pass">
                <el-input type="text" v-model="username" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="checkPass">
                <el-input type="password" v-model="password" autocomplete="off"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="handleLogin">登录</el-button>
                <el-button @click="ruleForm">重置</el-button>
            </el-form-item>

        </el-form>
    </div>

</template>

<script>
    export default {
        name: "Login.vue",
        data(){
            return{
                username:"",
                password:"",
                msg:"",

            }
        },
        methods:{
            ruleForm(){
                this.username="", this.password="", this.msg=""
            },
            handleLogin(){
                this.axios.post("http://localhost:8080/login",
                    this.qs.stringify({"username":this.username,"password":this.password}))
                    .then(result => {
                        if(result.data.status == "OK"){
                            //如果登录成功，就获得token,保存到本地
                            localStorage.setItem("username",result.data.data.username);
                            console.log(localStorage.getItem("username"))

                            localStorage.setItem("token",result.data.data.token);
                            //跳转到menu页面
                            this.$router.push({path:"/Menu"});
                        }else{
                            this.msg = "账号或密码错误";
                        }
                    });
            }
        }
    }
</script>

<style scoped>
    .login-container {
        position: absolute;
        width: 100%;
        height: 100%;
        overflow: hidden;
        /*background-image: url("../../assets/bgg.jpg");*/
        background-size: 100% 100%;
        background-repeat: no-repeat;
    }

</style>